/**
 * 获取key等于value的对象
 * @param key
 * @param value
 */
export const jsonArrayGet = (jsonArray:{}[], key:string, value:any)=>{
  return jsonArray.filter((p) => {
    return p[key] == value;
  });
}

/**
 * 获取key等于value的对象的索引
 * @param key
 * @param value
 */
export const jsonArrayGetIndex = (jsonArray:{}[], key:string, value:any)=>{
  let index;
  // 获取该对象
  let o:{} = jsonArrayGet(jsonArray, key, value);
  if(o !== undefined){
    // 获取该对象的索引
    index = jsonArray.indexOf(o[0]);
  }
  return index;
}

/**
 * 删除key等于value的对象
 * @param key
 * @param value
 */
export const jsonArrayRemove = (jsonArray:{}[], key:string, value:any)=>{
  // 获取该对象的索引
  let index = jsonArrayGetIndex(jsonArray, key, value)
  if(index !== undefined){
    index > -1 && jsonArray.splice(index, 1);
  }
}
